package cn.b.sky.flowable.cmd;

import cn.b.sky.common.exception.InfoException;
import cn.b.sky.flowable.utils.CustomProcessDiagramGenerator;
import org.flowable.engine.common.impl.interceptor.Command;
import org.flowable.engine.common.impl.interceptor.CommandContext;

import java.io.InputStream;

public class HistoryProcessInstanceDiagramCmd implements Command<InputStream> {
  protected String historyProcessInstanceId;

  public HistoryProcessInstanceDiagramCmd(String historyProcessInstanceId) {
    this.historyProcessInstanceId = historyProcessInstanceId;
  }

  @Override
  public InputStream execute(CommandContext commandContext) {
    try {
      CustomProcessDiagramGenerator customProcessDiagramGenerator = new CustomProcessDiagramGenerator();

      return customProcessDiagramGenerator.generateDiagram(historyProcessInstanceId);
    } catch (Exception ex) {
      throw new InfoException(ex);
    }
  }
}
